package com.aloda.ojsandbox.pojo.enums;

import org.springframework.util.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author aloda
 * @Date 2025/5/1 14:00
 */
public enum ResponseEnum {

    SUCCESS("执行成功", 200),
    FAILURE("执行失败", 500),
    CODE_SANDBOX_DISABLED("代码沙箱未启用", 50001),
    FILE_SAVE_ERROR("文件保存错误", 50002),
    COMPILE_FILE_FAILURE("编译失败", 50003),
    COMPILE_FILE_ERROR("编译错误", 50004),
    CODE_RUN_ERROR("程序执行异常", 50005),
    RESULT_GET_ERROR("结果处理异常", 50006),

    PARAM_ERROR("参数错误", 400),
    ;

    /**
     * 接口信息
     */
    private final String message;

    /**
     * 执行状态
     */
    private final Integer status;

    ResponseEnum(String message, Integer status) {
        this.message = message;
        this.status = status;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<Integer> getValues() {
        return Arrays.stream(values()).map(item -> item.status).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static ResponseEnum getEnumByValue(Integer value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (ResponseEnum anEnum : ResponseEnum.values()) {
            if (anEnum.status.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }

    public Integer getStatus() {
        return status;
    }

    public String getMessage() {
        return message;
    }
}
